# gozerlib/gozernet/bot.py
#
#

""" gozernet bot. handlers incoming nodes. """

## gozerlib imports

from gozerlib.xmpp.bot import XMPPBot
from event import RemoteEvent

import logging

class GozerNetBot(XMPPBot):

    """ gozernet bot just inherits from xmpp bot for now. """

    def __init__(self, name, cfg=None, outs=[]):
        XMPPBot.__init__(self, name, cfg)
        self.cfg['type'] = 'gozernet'
        self.type = "gozernet"
        self.outs = outs

    def say(self, channel, txt, event={}, *args, **kwargs):
        logging.warn('gozernet - out - %s - %s' % (channel, txt))
        re = RemoteEvent()
        re.copyin(event)  
        re.userhost = "%s.%s" % (self.name, self.server or 'hb-bot.appspot.com')
        re.nick = ""
        re.isreply = True
        re.iscallback = False
        re.fromm = self.jid  
        re.txt = re.origtxt = txt
        re.iscmnd = False
        re.botoutput = True
        re.isresponse = True
        re.remotecmnd = False
        XMPPBot.say(self, channel, re.tojson(), *args, **kwargs)

    def cmnd(self, outs, event, txt, *args, **kwargs):
        logging.warn('gozernet - cmnd - %s - %s' % (outs, txt))
        re = RemoteEvent()
        re.copyin(event)

        for jid in outs:
            re.isreply = True
            re.printto = jid
            re.target = jid
            re.txt = re.origtxt = txt
            re.iscmnd = True
            re.remotecmnd = True
            re.remoteout = self.jid
            XMPPBot.say(self, jid, re.tojson(), *args, **kwargs)
